package com.ruoyi.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.mapper.BalanceMapper;
import com.ruoyi.pojo.Balance;
import com.ruoyi.service.BalanceService;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

//@Service
@DubboService // 暴露服务  通过这个配置可以基于 Spring Boot 去发布 Dubbo 服务。
public class BalanceServiceImpl   implements BalanceService {

    @Resource
    private BalanceMapper balanceMapper;

    @Override
    public List<Balance> getBalanceList() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.err.println("------进来了-----被调用了--------");
        return balanceMapper.getList();
    }

    @Override
    public boolean insertBalance(Balance balance) {
        int insert = balanceMapper.insert(balance);
        System.err.println("我是用于余额插入，状态-------"+insert);
        if(insert == 1){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateBalance(Balance balance) {
        Balance balance1 = balanceMapper.selectById(balance.getId());
        //剩余金额
        BigDecimal subtract = balance1.getUserPrice().subtract(balance.getUserPrice());
        balance1.setUserPrice(subtract);
        int i = balanceMapper.updateById(balance1);
        System.err.println("我是用于余额修改，状态-------"+i);
        if(i == 1){
            return true;
        }
        return false;
    }

    @Override
    public String sayHello(String name) {
        return "我是balance服务，你好：" + name;
    }


}
